package com.bytedance.scenedemo.benchmark.performance;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.architecture_patterns.mvvm.ViewModelSceneSamples;
import com.bytedance.scenedemo.navigation.popto.PopToScene;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ScrollView;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

/**
 * Created by JiangQi on 8/21/18.
 */
public class PerformanceDemo extends Scene implements Component.ClickedListener{
    private static long startTimestamp = 0;

    public static long getStartTimestamp() {
        return startTimestamp;
    }

    public static void setStartTimestamp(long startTimestamp) {
        PerformanceDemo.startTimestamp = startTimestamp;
    }

    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_performance_demo,container,false);
        ScrollView svMain = (ScrollView) layout.findComponentById(ResourceTable.Id_sv_push_pop_basic_usage_main);
        Text textHint = (Text) layout.findComponentById(ResourceTable.Id_text_performance_demo_hint);
        Text title_content = (Text) layout.findComponentById(ResourceTable.Id_title_content);
        title_content.setTextColor(new Color(Color.getIntColor("#000000")));
        Button compare_btn_1 = (Button) layout.findComponentById(ResourceTable.Id_btn_nav_compare_btn_1);
        Button compare_btn_2 = (Button) layout.findComponentById(ResourceTable.Id_btn_nav_compare_btn_2);
        compare_btn_1.setClickedListener(this);
        compare_btn_2.setClickedListener(this);
        int value=0;
        if(getArguments()!=null){
            value= (int) getArguments().getParam("value");
        }
        svMain.setBackground(ColorUtil.getMaterialColor(value));
        textHint.setText(getClassName());

        return layout;
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_btn_nav_compare_btn_1:
                setStartTimestamp(System.currentTimeMillis());
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getAbility().getBundleName())
                        .withAbilityName(EmptyAppCompatAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                SceneExtensions.requireNavigationScene(this).startAbility(intent);
                break;
            case ResourceTable.Id_btn_nav_compare_btn_2:
                setStartTimestamp(System.currentTimeMillis());
                SceneExtensions.requireNavigationScene(this).push(EmptyAppCompatScene.class);
                break;
            default:
        }
    }
}
